package com.leyou.contrlloer;

import com.leyou.dto.CategoryDto;
import com.leyou.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/category")
@RestController  //返回的是数据，不加返回的是页面
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    /**
     * 接受的参数注解：
     *
     * @param pid
     * @return
     * @RequestParam
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDto>> saveItem(@RequestParam("pid") Long pid) {
        List<CategoryDto> categoryDtos = categoryService.findByParent(pid);
        return ResponseEntity.ok(categoryDtos);
    }

    @GetMapping("/list")
    public ResponseEntity<List<CategoryDto>> findCategoriesByIds(@RequestParam("ids") List<Long> ids) {
        List<CategoryDto> categoriesByIds = categoryService.findCategoriesByIds(ids);
        return ResponseEntity.ok(categoriesByIds);
    }
}
